import userConstant from "../constants/user";

export interface IUser {
  title: string;
  count: number;
  userInfo: any;
  token: string | null;
}

const userState: IUser = {
  title: "login",
  count: 5,
  userInfo: {},
  token: null,
};

const userReducer = (state = userState, action: any) => {
  const { type, payload } = action;
  const { USER_LOGIN } = userConstant;
  switch (type) {
    case USER_LOGIN: {
      return { ...state, userInfo: payload.userInfo, token: payload.token };
    }
    default: {
      return { ...state };
    }
  }
};

export default userReducer;
